#pragma once
#include "libMediaCapture.h"
#include "MediaSampleGrabberCB.h"

class MediaCapTool
{
public:
	MediaCapTool();
	~MediaCapTool();

	static void ListDevice(std::list<std::string>* pDeviceVideo, std::list<std::string>* pDeviceAudio);
	static int FindVideoDevice(const char* strExNameList);

	bool Init(MediaCaptureVideoInfo* pInfoVideo, MediaCaptureAudioInfo* pInfoAudio);

	bool AddAudioLink(MediaCaptureAudioInfo* pInfoAudio);
	bool AddVideoLink(MediaCaptureVideoInfo* pInfoVideo);

	void SetVideoCBFunc(MediaCapture_CB pFunc, bool bRaw=false);
	void SetAudioCBFunc(MediaCapture_CB pFunc, bool bRaw=false);

	void Stop();

	void GetSPSAndPPS(unsigned char*sps, long&spslen, unsigned char*pps, long&ppslen);

	bool SetCameraExposure(bool bAuto, int nVal);

private:
	static void _SplitList(std::string strSrc, std::string strDot, std::list<std::string>& strOut);
	static bool _FindInList(std::string strSrc, std::list<std::string> &strList);
private:
	IGraphBuilder *m_pGraphBuilder = NULL;
	ICaptureGraphBuilder2 *m_pCaptureBuilder = NULL;
	IMediaControl *m_pMediaControl = NULL;

	IBaseFilter *m_pAudioDevice = NULL;
	IBaseFilter *m_pAudioDeviceGrabber = NULL;
	IBaseFilter *m_pAudioDeviceNullRender = NULL;
	ISampleGrabber *m_pAudioSampleGrabber = NULL;
	IAMStreamConfig *m_pAudioConfig = NULL;
	AM_MEDIA_TYPE *m_pAudioFmtConfig = NULL;
	bool m_bAudioFind = false;
	MediaSampleGrabberCB m_SampleCBAudio;

	IAMCameraControl* m_pCameraCtl = NULL;
	IBaseFilter *m_pVideoDevice = NULL;
	IBaseFilter *m_pVideoDeviceGrabber = NULL;
	IBaseFilter *m_pVideoDeviceNullRender = NULL;
	ISampleGrabber *m_pVideoSampleGrabber = NULL;
	IAMStreamConfig *m_pVideoConfig = NULL;
	AM_MEDIA_TYPE *m_pVideoFmtConfig = NULL;
	bool m_bVideoFind = false;
	MediaSampleGrabberCB m_SampleCBVideo;
};

